﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace JiaBao.WPF.Framework.Controls
{
    public class ListBoxItemEx : ListBoxItem
    {
        static ListBoxItemEx()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(ListBoxItemEx), new FrameworkPropertyMetadata(typeof(ListBoxItemEx)));
        }

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            CheckBox ck = Template.FindName("ck_Item", this) as CheckBox;
            if (null != ck)
            {
                ck.Checked += (object sender, RoutedEventArgs e) =>
                {
                    IsChecked = true;
                };

                ck.Unchecked += (object sender, RoutedEventArgs e) =>
               {
                   IsChecked = false;
               };
            }
        }



        private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            d.SetValue(e.Property, e.NewValue);
        }
        /// <summary>
        /// 是否选中
        /// </summary>
        public bool IsChecked
        {
            get { return (bool)GetValue(IsCheckedProperty); }
            set { SetValue(IsCheckedProperty, value); }
        }
        public static readonly DependencyProperty IsCheckedProperty =
            DependencyProperty.Register("IsChecked", typeof(bool), typeof(ListBoxItemEx), new PropertyMetadata(false, OnPropertyChanged));

        /// <summary>
        /// data
        /// </summary>
        public int ItemData
        {
            get { return (int)GetValue(ItemDataProperty); }
            set { SetValue(ItemDataProperty, value); }
        }
        public static readonly DependencyProperty ItemDataProperty =
            DependencyProperty.Register("ItemData", typeof(int), typeof(ListBoxItemEx), new PropertyMetadata(-1, OnPropertyChanged));



        /// <summary>
        /// 显示
        /// </summary>
        public new string Content
        {
            get { return (string)GetValue(ContentProperty); }
            set { SetValue(ContentProperty, value); }
        }
        public new static readonly DependencyProperty ContentProperty =
            DependencyProperty.Register("Content", typeof(string), typeof(ListBoxItemEx), new PropertyMetadata("", OnPropertyChanged));

    }
}
